<!doctype html>
<html>

	<head>
		<meta charset="UTF-8">
		<title></title>
		<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
		<link href="../css/mui.min.css" rel="stylesheet" />
		<link rel="stylesheet" type="text/css" href="../css/style.css" />
		<link rel="stylesheet" href="../css/iconfont.css" />
		<link rel="stylesheet" href="../css/wallet.css" />
		<link rel="stylesheet" href="../css/font-awesome.min.css" />
		<link rel="stylesheet" href="../css/bootstrap.min.css" />
	</head>
<style>
		body {
			background: #f0f0f0;
		}
		
		.container-fill {
			padding: .5em;
		}
		
		.text-muted {
			color: #ddd;
		}
		
		.text-orange {
			color: #f15a0c;
		}
		
		h4 {
			margin: 5px 0;
		}
		
		h4:first-of-type {
			margin-top: 10px;
		}
		
		.panel {
			padding: .5em;
			margin-bottom: 10px;
		}
		
		.nav.nav-tabs {
			margin-bottom: .8em;
		}
		
		.alert .form-group {
			margin-bottom: 0;
		}
		
		label.form-group {
			display: block;
		}
		
		label.form-group {
			font-weight: normal;
			overflow: hidden;
			border-top: 1px #DDD solid;
			padding-top: 10px;
			padding-bottom: 0;
			margin-bottom: 0
		}
		
		label.form-group .col-xs-2 {
			margin-top: 0px;
		}
		
		label.form-group .col-xs-2 i {
			margin-top: 10px;
		}
		
		label.form-group input[name="type"] {
			opacity: 0;
			width: 0;
		}
		
		.pay-info p.bb {
			border-top: 1px #ddd dashed;
			padding: 10px 5px 0px;
		}
		
		.pay-info p.b1 {
			padding: 0px 5px;
		}
		
		a.btn.btn-block.js-pay {
			margin: 12px 0;
		}
		#pay_money{text-align: left;}
	</style>
	<body>
		<header class="mui-bar mui-bar-nav">
			<a class=" mui-icon mui-icon-left-nav mui-pull-left" href="JavaScript:history.go(-1)"></a>
			<h1 class="mui-title">充值</h1>
		</header>
		<div class="mui-content">
			<ul class="bank_list">
				<li class="clearfix">
					<label>账&nbsp;&nbsp;&nbsp;号</label>
					<input type="text" placeholder="充值帐号" id="user_accoun"  disabled="disabled"/>
				</li>
				<li class="clearfix">
					<label>金&nbsp;&nbsp;&nbsp;额</label>
					<input type="text" placeholder="请输入充值金额" id="pay_money" />
				</li>
			</ul>
			<div class="pay_paystyle">
				<div class="recha_bt"><span class="iconfont icon-xiaofeidejifen"></span>付款方式</div>
				<div class="panel" style="border-top-left-radius:0; border-top-right-radius:0;">
					<div class="tab-content">
						<div class="tab-pane animated active fadeInLeft" id="direct">
							<div class="clearfix">
								<a class="btn btn-info btn-block js-pay js-m js_zfb" style="display: none;" data-type="3" href="javascript:;">支付宝支付</a>
								<a class="btn btn-success btn-block js-pay js-m js-wx" style="display: none;" data-type="2" href="javascript:;">微信支付</a>
								<!--<a class="btn btn-warning btn-block js-pay js-m" data-type="4" href="javascript:;">银联支付</a>-->
							</div>
						</div>
					</div>
				</div>
			</div>
			<!--<div class="wallet_btn">
				<a href="#" onclick="submit_tx()">确认</a>
			</div>-->
		</div>
		<input type="hidden" id='order_sn'>
		<div id="callback"></div>
		<div id="cut_back"></div>
	</body>
</html>

	<script type="text/javascript" src="../js/date.js"></script>

	<script type="text/javascript" src="../js/jquery.min.js"></script>
	<script type="text/javascript" src="../js/layer/layer.min.js"></script>
		<script type="text/javascript" src="../js/app.js"></script>
	<script>
			var pay_type = 0;
			var ua = window.navigator.userAgent.toLowerCase();
			if(ua.match(/MicroMessenger/i) == 'micromessenger') {
				pay_type = 2;
				$('#js_zfb').show();
			} else if(ua.match(/AlipayClient/i) == 'alipayclient') {
				pay_type = 3;
				$('#js-wx').show();
			}
		$(function() {
			var member = JSON.parse(localStorage.getItem('member'));
			$("#balance").text("￥" + member.credit2 + "元");
		    if(ua.match(/MicroMessenger/i)=="micromessenger") {
		    } else {
		    	$(".js-wx").text("微信支付(仅限微信浏览器)");
		    }
			
			checkLogin(APP.web_root+"member/login.html");
			var member = JSON.parse(localStorage.getItem('member'));
			$("#user_accoun").val(member['mobile']);
		
			$(".btn-primary").click(function() {
				$(".modal").addClass("in");
				$(".modal").show();
			})
			$(".js-m").click(function() {
				
				//订单编号
				$('#order_sn').val(getSn());
				
				var pay_type=$(this).data("type");
				$("#cut_pay_type").val(pay_type);
				var act="alipay";
				var jstype="html";
				var openid=member['openid'];
				if(openid==""){
					openid=localStorage.getItem("openid");
				}
				if(pay_type==2){
					act="wechat";
					jstype="jsonp";
				}else if(pay_type==4){
					act="unionpay";
				}
			
				$.ajax({
					url: APP.api_url + 'Payment/'+act,
					data: {
						WIDout_trade_no	: $('#order_sn').val(),
						WIDsubject		: "账号充值",
						WIDtotal_fee	: $("#pay_money").val(),
						return_url		: APP.web_root+"member/index.html",
						WIDshow_url		: 'www',
						WIDbody			: "账号充值",
						uid				: getUid(),
						order_ids		: 0,
						type			: "recharge",
						user_type		: member['agent_type'],
						token			: get_token(),
						openid			: openid,
						pay_type		: pay_type
					},
					type: "post",
					dataType:jstype,
					jsonp:'callback',  
					jsonpCallback :'jsonpCallback',
					success: function(data) {
						$("#post_sn").val($("#order_no").text()); 
						$("#post_money").val($("#pay_money").val());
						if(pay_type==2){
							callpay(data);
						}else{
							$("#callback").append(data);
						}
						if(pay_type==4){
							$("#pay_form").submit();
						}
					}
				})
			})
		function jsonpCallback(data){
			
			$("#cut_back").append(data);
		}
			//调用微信JS api 支付
		function jsApiCall(jsApiParameters) {
			WeixinJSBridge.invoke('getBrandWCPayRequest', jsApiParameters,
				function(res) {
					if(res.err_msg == "get_brand_wcpay_request:ok") {
						$("#pay_status").val(2);
						alert('支付成功');
					} else {
						$("#pay_status").val(1);
						alert('支付失败');
					}
				}
			);
		}

		function callpay(jsApiParameters) {
			console.log(jsApiParameters);
			if(typeof WeixinJSBridge == "undefined") {
				if(document.addEventListener) {
					document.addEventListener('WeixinJSBridgeReady', jsApiCall(jsApiParameters), false);
				} else if(document.attachEvent) {
					document.attachEvent('WeixinJSBridgeReady', jsApiCall(jsApiParameters));
					document.attachEvent('onWeixinJSBridgeReady', jsApiCall(jsApiParameters));
				}
			} else {
				jsApiCall(jsApiParameters);
			}
		}
		
	//===================付款end=================================
		function jsonpCallback(data){
			
		}
			//调用微信JS api 支付
		function jsApiCall(jsApiParameters) {
			WeixinJSBridge.invoke('getBrandWCPayRequest', jsApiParameters,
				function(res) {
					if(res.err_msg == "get_brand_wcpay_request:ok") {
						
						alert('支付成功');
					} else {
						alert('支付失败');
					}
				}
			);
		}

		function callpay(jsApiParameters) {
			console.log(jsApiParameters);
			if(typeof WeixinJSBridge == "undefined") {
				if(document.addEventListener) {
					document.addEventListener('WeixinJSBridgeReady', jsApiCall(jsApiParameters), false);
				} else if(document.attachEvent) {
					document.attachEvent('WeixinJSBridgeReady', jsApiCall(jsApiParameters));
					document.attachEvent('onWeixinJSBridgeReady', jsApiCall(jsApiParameters));
				}
			} else {
				jsApiCall(jsApiParameters);
			}
		}
	})
	</script>